<template>
  <NavBack title="更改收货地址"></NavBack>

  <van-address-edit
    :area-columns-placeholder="['请选择', '请选择', '请选择']"
    :area-list="areaList"
    :address-info="AddressEditInfo"
    show-delete
    show-set-default
    @save="onSave"
    @delete="onDelete"
  />
</template>
  
  <script>
import { areaList } from "@vant/area-data";
import NavBack from "../../components/NavBack.vue";
import { showSuccessToast } from "vant";
import { showConfirmDialog } from "vant";
export default {
  components: {
    NavBack,
  },
  data() {
    return {
      list: [],
      areaList,
    };
  },
  created() {
    this.list = JSON.parse(this.$route.query.infodata);
    this.AddressEditInfo = JSON.parse(this.$route.query.infodata);
    // console.log(this.list);
  },
  methods: {
    onSave(info) {
      // /address/update
      //   console.log(info);
      this.$http({
        url: "/address/update",
        method: "post",
        data: {
          addressid: info.addressid,
          userid: info.userid,
          name: info.name,
          tel: info.tel,
          province: info.province,
          city: info.city,
          county: info.county,
          addressDetail: info.addressDetail,
          isDefault: info.isDefault,
        },
      }).then((res) => {

        showSuccessToast("修改成功");
        this.$router.push("/myaddress");
      });
    },
    // /address/delete     addressid

    onDelete(info) {
      showConfirmDialog({
        title: "删除地址",
        message: "确认删除这个地址嘛",
      })
        .then(() => {
          this.$http({
            url: "/address/delete",
            method: "post",
            data: {
              addressid: info.addressid,
            },
          }).then((res) => {
            if(res.data.code == '200'){
                this.$router.push('./myaddress')
            }
            
          });
        })
        .catch(() => {
          // on cancel
        });
    },
  },
};
</script>
  
  <style>
</style>